package com.chem.lems.controller;

import com.alibaba.fastjson.JSONObject;
import com.chem.lems.serves.BackupServices;
import com.chem.lems.utils.ResultUtil;
import com.chem.lems.vo.BackupBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("backup")
public class BackupController {

    @Autowired
    private BackupServices backupServices;

    /**
     * 获取备份记录
     *
     * @return
     */
    @GetMapping()
    public ResultUtil getBackup() {
        return backupServices.queryBackup();
    }
    /**
     * 获取备份记录
     *
     * @return
     */
    @GetMapping("date")
    public ResultUtil getBackupDate() {
        return backupServices.getBackupDate();
    }
    /**
     * 数据库备份
     *
     * @param backupBO
     * @return
     */
    @PostMapping()
    public ResultUtil backup(@RequestBody BackupBO backupBO) {
        return backupServices.backup(backupBO);
    }

    /**
     * 数据还原
     *
     * @param backupBO
     * @return
     */
    @PutMapping()
    public ResultUtil restore(@RequestBody BackupBO backupBO) {
        return backupServices.restore(backupBO);
    }


    /**
     * 删除备份记录
     * @param title
     * @param path
     * @return
     */
    @DeleteMapping("{title}/{path}")
    public ResultUtil delBackup(@PathVariable("title") String title, @PathVariable("path") String path) {
        return backupServices.delBackup(title,path);
    }

}
